package com.seteam.collabcrossword;

import com.seteam.collabcrossword.exceptions.CollabCrosswordException;

import java.io.Serializable;

/**
 * This class is an extension of {@link Crossword}. It contains the solution
 * to the crossword.
 */
public class CrosswordSolution extends Crossword implements Serializable {
    private static final long serialVersionUID = -293761115834313160L;
    private Tile[][] solution;

    /**
     * Constructor
     *
     * @param x the width of the board
     * @param y the height of the board
     * @throws CollabCrosswordException if the width or height is negative
     */
    public CrosswordSolution(final int x, final int y) throws CollabCrosswordException {
        super(x, y);
    }

    /**
     * Given an array of tiles, this method checks them against the actual solution
     * and tells whether the solution is right or not
     *
     * @param board the array of tiles to be checked
     * @return <tt>TRUE</tt> if the passed board matches the actual solution
     *         <tt>FALSE</tt> otherwise
     */
    public boolean checkSolution(final Tile[][] board) {
        for (int row = 0; row < board.length; row++) {
            for (int column = 0; column < board[row].length; column++) {
                if (!board[row][column].equals(solution[row][column])) {
                    return false;
                }
            }
        }
        return true;
    }

    /**
     * Setter for solution
     *
     * @param solution an array of tiles that represents the solution
     */
    public void setSolution(final Tile[][] solution) {
        this.solution = solution;
    }

    /**
     * Getter for solution
     *
     * @return an array of tiles that represents the solution
     */
    public Tile[][] getSolution() {
        return solution;
    }
}
